package colthgame.app;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Point;
import android.graphics.Rect;

public class Character extends RenderGameObject
{
	public Character()
	{
		super(BaseGameObject.E_Type.eCHARACTER);
		SetPosX(143);
		SetPosY(254);
		SetWidth(285);
		SetHeight(508);

		m_rectCharacter = new Rect(GetPosX() - GetWidth_Half(), GetPosY() - GetHeight_Half(), GetPosX()
				+ GetWidth_Half(), GetPosY() + GetHeight_Half());

		m_CostumeOffset = new Point[ItemCostume.E_Layer.eMAX.ordinal()];
		m_CostumeSize = new Point[ItemCostume.E_Layer.eMAX.ordinal()];
		m_rectCostume = new Rect[ItemCostume.E_Layer.eMAX.ordinal()];
		m_bRender = new boolean[ItemCostume.E_Layer.eMAX.ordinal()];
		m_arItemCostumes = new ItemCostume[ItemCostume.E_Layer.eMAX.ordinal()];

		for (int nIndex = 0; nIndex < ItemCostume.E_Layer.eMAX.ordinal(); nIndex++)
		{
			m_CostumeOffset[nIndex] = ClothgameResourceMgr.GetInstance().GetCostumeOffset(ItemCostume.ELayer[nIndex]);
			m_CostumeSize[nIndex] = ClothgameResourceMgr.GetInstance().GetCostumeCollisionSize(
					ItemCostume.ELayer[nIndex]);
			m_rectCostume[nIndex] = CalculateCostumePos(m_CostumeOffset[nIndex], m_CostumeSize[nIndex]);
			m_bRender[nIndex] = false;
			m_arItemCostumes[nIndex] = null;
		}
	}

	@Override
	public void Render(Canvas _canvas)
	{
		// TODO Auto-generated method stub
		super.Render(_canvas);
		Paint p = new Paint();
		p.setColor(Color.YELLOW);
		p.setStyle(Style.STROKE);
		for (int nIndex = 0; nIndex < ItemCostume.E_Layer.eMAX.ordinal(); nIndex++)
		{
			if (true == m_bRender[nIndex])
			{
				_canvas.drawRect(m_rectCostume[nIndex], p);
			}
		}
		_canvas.drawRect(m_rectCharacter, p);

	}

	public boolean Intersect(ItemCostume.E_Layer _eLayer, Rect _rect)
	{
		return Rect.intersects(m_rectCostume[_eLayer.ordinal()], _rect);
	}

	public void SetRender(ItemCostume.E_Layer _eLayer, boolean _bRender)
	{
		m_bRender[_eLayer.ordinal()] = _bRender;
	}

	public Point GetCostumePos(ItemCostume.E_Layer _eLayer)
	{
		Point result = new Point(m_rectCostume[_eLayer.ordinal()].centerX(), m_rectCostume[_eLayer.ordinal()].centerY());
		return result;
	}

	private Rect CalculateCostumePos(Point Offset, Point Size)
	{
		Rect Result = new Rect();
		Result.left = GetPosX() - GetWidth_Half() + Offset.x;
		Result.top = GetPosY() - GetHeight_Half() + Offset.y;
		Result.right = GetPosX() - GetWidth_Half() + Offset.x + Size.x;
		Result.bottom = GetPosY() - GetHeight_Half() + Offset.y + Size.y;
		return Result;
	}

	public void SetEquipment(ItemCostume.E_Layer _eLayer, ItemCostume _ItemCostume)
	{
		m_arItemCostumes[_eLayer.ordinal()] = _ItemCostume;
	}

	public boolean IsEqualEquipment(ItemCostume.E_Layer _eLayer, ItemCostume _ItemCostume)
	{
		if( null == _ItemCostume )
			return false;
		
		if( null == m_arItemCostumes[_eLayer.ordinal()] )
			return false;
		
		if( _ItemCostume == m_arItemCostumes[_eLayer.ordinal()] )
			return true;
		
		return false;
	}

	private Point	m_CostumeOffset[];	// ĳ���� �������� ������ �����°�
	private Point	m_CostumeSize[];	// ĳ���� �������� ������ ũ��
	private Rect	m_rectCostume[];
	private boolean	m_bRender[];
	private Rect	m_rectCharacter;
	private ItemCostume	m_arItemCostumes[];

}
